// 鐧惧害鍦板浘API鍔熻兘
function showMap( lng, lat, address ) {
    var map = new BMap.Map("allmap");
    var point = new BMap.Point(lng,lat);
    map.centerAndZoom(point,15);
    var marker = new BMap.Marker(point);  // 鍒涘缓鏍囨敞
    map.addOverlay(marker);              // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
    marker.setAnimation(BMAP_ANIMATION_BOUNCE); //璺冲姩鐨勫姩鐢�
    var label = new BMap.Label( address,{offset:new BMap.Size(20,-10)});
    marker.setLabel(label);
    map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_ZOOM}));  //鍙充笅瑙掞紝浠呭寘鍚缉鏀炬寜閽�
}
function createMap( lng, lat, address, city ) {
    var map = new BMap.Map("allmap");
    var point = new BMap.Point(lng,lat);
    var marker;
    var gc;
    map.centerAndZoom(point,13);

    if( lng == "0.000000" && lat == "0.000000" ) {
        if( city == "" ) {
            var myCity = new BMap.LocalCity();
            myCity.get(function(result){
                var cityName = result.name;
                if( address == "" )
                    map.setCenter(cityName);
            });
        } else {
            map.setCenter(city);
        }
        if( address != "" ) {
            gc = new BMap.Geocoder();
            gc.getPoint( address, function(p){
                if (p) {
                    map.centerAndZoom(p, 16);
                    marker = new BMap.Marker(p);  // 鍒涘缓鏍囨敞
                    map.addOverlay(marker);              // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
                    marker.setAnimation(BMAP_ANIMATION_BOUNCE); //璺冲姩鐨勫姩鐢�
                    var label = new BMap.Label( address,{offset:new BMap.Size(20,-10)});
                    marker.setLabel(label);
                    $("#LONGITUDE").val( p.lng );
                    $("#LATITUDE").val( p.lat );
                }
            });
        }
    } else {
        marker = new BMap.Marker(point);  // 鍒涘缓鏍囨敞
        map.addOverlay(marker);              // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
        marker.setAnimation(BMAP_ANIMATION_BOUNCE); //璺冲姩鐨勫姩鐢�
        var label = new BMap.Label( address,{offset:new BMap.Size(20,-10)});
        marker.setLabel(label);
    }

    map.addControl(new BMap.NavigationControl());  //娣诲姞榛樿缂╂斁骞崇Щ鎺т欢
    gc = new BMap.Geocoder();
    map.addEventListener("click", showInfo);

    function showInfo(e){
        var pt = e.point;
        gc.getLocation(pt, function(rs){
            if( marker ) {
                marker.hide();
            }
            marker = new BMap.Marker(e.point);  // 鍒涘缓鏍囨敞
            map.addOverlay(marker);              // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
            marker.setAnimation(BMAP_ANIMATION_BOUNCE); //璺冲姩鐨勫姩鐢�

            var addComp = rs.addressComponents;
            var label = new BMap.Label( addComp.city + addComp.district + addComp.street + addComp.streetNumber,{offset:new BMap.Size(20,-10)});
            marker.setLabel(label);

            $("#ADDRESS").val( addComp.city + addComp.district + addComp.street + addComp.streetNumber );
            $("#LONGITUDE").val( e.point.lng );
            $("#LATITUDE").val( e.point.lat );
        });
    }
}